#include <bits/stdc++.h>
#include <cstdio>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
set<int> q;
map<int, int> l;
map<int, int> r;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    q.insert(a[0]);
    int ans;
    for(int i = 1; i < n; i++)
    {
        set<int>::iterator pos = q.lower_bound(a[i]);
        if(pos != q.end() && l[*pos] == 0)
        {
            ans = *pos;
            l[*pos] = a[i];
        }
        else
        {
            pos--;
            ans = *pos;
            r[*pos] = a[i];
        }
        cout << ans << ' ';
        q.insert(a[i]);
    }
    cout << endl;
    return 0;
}
